<?php
/**
 * Created by PhpStorm.
 * User: minicart
 * Date: 2018/9/22
 * Time: 16:10
 */
namespace app\models;
use think\Model;

/**
 * Class ConsultorModel
 * @package app\models
 */
class ConsultorModel extends Model
{
    protected $table = 'edu_consultor';

    /**
     * 订单列表 分页
     * @param array $where
     * @param int $page
     * @param int $limit
     * @param string $order
     * @param string $time
     * @return array
     * @throws \think\exception\DbException
     */
    public static function pageLists($where = [], $page = 1, $limit = 5, $order = 'id desc', $time = '')
    {
        $result = self::where($where)->order($order)->paginate($limit, false, ['page' => $page]);
        if (!$result->total()) {
            return ['code' => 0, 'msg' => "ok", 'count' => 0, 'data' => []];
        }
        foreach ($result as $value) {
            $student = StudentModel::get($value['student_id']);
            $contract = ContractModel::get(['contract_number'=>$value['contract_number']]);
            $value['channel'] = DictionaryModel::where('id',$student['channel'])->value('name') ? : '-';
            $value['grade'] = DictionaryModel::where('id',$student['grade'])->value('name');
            $value['phone'] = $student['phone'];
            $value['student_name'] = $student['student_name'];
            $value['name'] = $student['name'];
            $value['contract_type'] = DictionaryModel::where('id',$value['contract_type'])->value('name');
            $value['signing_date'] = $contract['signing_date'];
            $value['total_amount'] = Number_format($contract['total_amount'] / 100,2);
            $value['amount'] = Number_format($contract['amount'] / 100,2);
        }
        $result = $result->toArray();
        return ['code' => 0, 'msg' => "ok", 'count' => $result['total'], 'data' => $result['data']];
    }
}
